package com.wenlong.agricultural.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 苏文龙
 * @version 1.0
 */
@Data
public class ResponseInfo {
    private Boolean flag;
    // 约定 200 表示成功 300 表失败
    private Integer code;
    private String message;
    private Map<String, Object> data = new HashMap<>();

    private ResponseInfo(){}

    public static ResponseInfo ok(){
        ResponseInfo r = new ResponseInfo();
        r.setFlag(true);
        r.setCode(200);
        r.setMessage("成功");
        return r;
    }

    public static ResponseInfo error(){
        ResponseInfo r = new ResponseInfo();
        r.setFlag(false);
        r.setCode(300);
        r.setMessage("失败");
        return r;
    }

    public ResponseInfo _flag(Boolean flag){
        this.setFlag(flag);
        return this;
    }

    public ResponseInfo _massage(String massage){
        this.setMessage(massage);
        return this;
    }

    public ResponseInfo _code(Integer code){
        this.setCode(code);
        return this;
    }

    public ResponseInfo _data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
}
